#define  _CRT_SECURE_NO_WARNINGS


struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};
 
class Solution {
public:
    bool IsBalanced_Solution(TreeNode* pRoot) {
        return Height(pRoot) != -1;
    }
    int Height(TreeNode* root)
    {
        if (!root) return 0;
        int left = Height(root->left) ;
        if (left == -1) return -1;
        int right = Height(root->right) ;
        if (right == -1) return -1;

        if (abs(left - right) > 1) return -1;
        return max(left, right) + 1;
    }
};